# ============================================
# .HTACCESS - Configurações de Segurança
# ============================================
# Coloque este arquivo na raiz da pasta /iptv/

# 1. Ativar rewrite engine
RewriteEngine On

# 2. Força HTTPS (descomente se usar SSL)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 3. Remove .php da URL (opcional)
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^([^\.]+)$ $1.php [NC, L]

# 4. Bloquear acesso a arquivos sensíveis
<FilesMatch "config\.php|database\.sql|\.env|\.git">
    Order allow,deny
    Deny from all
</FilesMatch>

# 5. Bloquear listagem de diretórios
Options -Indexes

# 6. Headers de segurança
<IfModule mod_headers.c>
    # Prevenir clickjacking
    Header set X-Frame-Options "SAMEORIGIN"
    
    # Prevenir MIME type sniffing
    Header set X-Content-Type-Options "nosniff"
    
    # Proteção XSS
    Header set X-XSS-Protection "1; mode=block"
    
    # Política de conteúdo (CSP)
    Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';"
    
    # Referrer Policy
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# 7. Aumentar limits de upload (se necessário)
<IfModule mod_php.c>
    php_value upload_max_filesize 100M
    php_value post_max_size 100M
    php_value max_execution_time 300
</IfModule>

# 8. Blocar bots
<IfModule mod_rewrite.c>
    # Bloquear SQL Injection
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} UNION.*SELECT [NC,OR]
    RewriteCond %{QUERY_STRING} INSERT.*INTO [NC,OR]
    RewriteCond %{QUERY_STRING} DELETE.*FROM [NC]
    RewriteRule ^.* - [F,L]
</IfModule>

# 9. Cache
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>
